<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateManagerOauthRelationsTable extends Migration
{
    private const TABLE = 'manager_oauth_relations';

    public function up()
    {
        Schema::create(self::TABLE, function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('manager_id')->default(0)->comment('管理员ID');
            $table->string('channel')->default('')->comment('登录渠道');
            $table->string('channel_appid')->default('')->comment('渠道APPID');
            $table->string('openid')->default('')->comment('openid');
            $table->string('unionid')->default('')->comment('unionid');
            $table->string('nickname')->default('')->comment('昵称');
            $table->string('avatar')->default('')->comment('头像');
            $table->timestamps();

            $table->index(['channel', 'channel_appid', 'openid']);
        });
        DB::statement("ALTER TABLE `".self::TABLE."` comment '管理员OAUTH关联'");
    }

    public function down()
    {
        Schema::dropIfExists(self::TABLE);
    }
}
